//
//  LCBaseViewController.m
//  LCPackage
//
//  Created by 马军凯 on 2021/6/22.
//  Copyright © 2021 龙采科技集团. All rights reserved.
//

#import "LCBaseViewController.h"
#import "LCNavigationViewController.h" //自定义Navigation

@interface LCBaseViewController ()
@property (nonatomic, assign) BOOL isLogin;
@end

@implementation LCBaseViewController

- (void)dealloc {
    NSLog(@"【%@】页面销毁", [self class]);
}

#pragma mark 页面将显示
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
#pragma mark 页面已显示
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    LCNavigationViewController *vc = (LCNavigationViewController *)self.navigationController;
    vc.panges.enabled = YES;
}
#pragma mark 页面要消失
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //背景颜色
    self.view.backgroundColor = [UIColor whiteColor];
    //初始化
    [self initAllView];
    //
    self.isLogin = YES;
}
#pragma mark 初始化
- (void)initAllView {
    [self view_noData];//没有数据
}
#pragma mark 是否隐藏导航栏
- (void)setHiddenBool:(BOOL)hiddenBool {
    if (hiddenBool == YES) {
        self.navigationController.navigationBar.hidden = YES;
        [self navigationBarBackView]; //navigation+status
        [self navigationBarView]; //navigation
        [self navigationLeftView]; //返回
        [self navigationTitleLabel]; //标题
        [self navigationLineView]; //线
    }
}
#pragma mark 导航栏点击事件
//返回
- (void)onNavigationLeftItem {
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}
//右侧
- (void)onNavigationRightItem {}
#pragma mark 导航栏右侧
//文字
- (void)setNavigationRightItemWithTitle:(NSString *)title {
    [self navigationRightView];
    //按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, self.navigationRightView.width, self.navigationRightView.height);
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleColor:[UIColor LC_hex:@"#000000"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onNavigationRightItem) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationRightView addSubview:btn];
}
//图片
- (void)setNavigationRightItemWithImage:(NSString *)imageString {
    [self navigationRightView];
    //按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, self.navigationRightView.width, self.navigationRightView.height);
    [btn setImage:[UIImage imageNamed:imageString] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onNavigationRightItem) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationRightView addSubview:btn];
}

#pragma mark 是否显示没有数据
- (void)isShowNoDataViewWith:(NSInteger)count {
    if (count == 0) {
//        self.view_noData.hidden = NO;
    } else {
//        self.view_noData.hidden = YES;
    }
}
#pragma mark 判断是否登录
- (BOOL)judgeIsLogin {
//    if (self.isLogin == YES) {
//        LCLoginViewController *vc = [[LCLoginViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//        return NO;
//    }
    return YES;
}












#pragma mark UITouch
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

#pragma mark 懒加载
//导航栏+状态栏  STATUS_AND_NAVIGATION_BAR_HEIGHT 高度
- (UIView *)navigationBarBackView {
    if (_navigationBarBackView == nil) {
        _navigationBarBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STATUS_AND_NAVIGATION_BAR_HEIGHT)];
        _navigationBarBackView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_navigationBarBackView];
    }
    return _navigationBarBackView;
}
//导航栏 44高度
- (UIView *)navigationBarView {
    if (_navigationBarView == nil) {
        _navigationBarView = [[UIView alloc] initWithFrame:CGRectMake(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, NAVIGATION_BAR_HEIGHT)];
        _navigationBarView.backgroundColor = [UIColor clearColor];
        [self.navigationBarBackView addSubview:_navigationBarView];
    }
    return _navigationBarView;
}
//返回
- (UIView *)navigationLeftView {
    if (_navigationLeftView == nil) {
        _navigationLeftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, NAVIGATION_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT)];
        _navigationLeftView.backgroundColor = [UIColor clearColor];
        [self.navigationBarView addSubview:_navigationLeftView];
        //按钮
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, _navigationLeftView.width, _navigationLeftView.height);
        [btn setImage:[UIImage imageNamed:@"navigationBar_left_black"] forState:UIControlStateNormal];
        btn.imageEdgeInsets = UIEdgeInsetsMake(7, 10, 7, 10); //设置一下
        [btn addTarget:self action:@selector(onNavigationLeftItem) forControlEvents:UIControlEventTouchUpInside];
        [_navigationLeftView addSubview:btn];
    }
    return _navigationLeftView;
}
//标题
- (UILabel *)navigationTitleLabel {
    if (_navigationTitleLabel == nil) {
        _navigationTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 200) / 2, 0, 200, NAVIGATION_BAR_HEIGHT)];
        _navigationTitleLabel.font = [UIFont boldSystemFontOfSize:16];
        _navigationTitleLabel.textAlignment = NSTextAlignmentCenter;
        _navigationTitleLabel.textColor = [UIColor LC_hex:@"#000000"];
        [self.navigationBarView addSubview:_navigationTitleLabel];
    }
    return _navigationTitleLabel;
}
//线
- (UIView *)navigationLineView {
    if (_navigationLineView == nil) {
        _navigationLineView = [[UIView alloc] initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT - 1, SCREEN_WIDTH, 1)];
        _navigationLineView.backgroundColor = [UIColor LC_hex:@"#F2F2F2"];
        [self.navigationBarView addSubview:_navigationLineView];
    }
    return _navigationLineView;
}
//右侧view
- (UIView *)navigationRightView {
    if (_navigationRightView == nil) {
        _navigationRightView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 80, 0, 80, NAVIGATION_BAR_HEIGHT)];
        _navigationRightView.backgroundColor = [UIColor clearColor];
        [self.navigationBarView addSubview:_navigationRightView];
    }
    return _navigationRightView;
}



//没有数据
- (LCNoDataView *)view_noData {
    if (_view_noData == nil) {
        _view_noData = [[NSBundle mainBundle] loadNibNamed:@"LCNoDataView" owner:nil options:nil].firstObject;
        _view_noData.frame = CGRectMake(0, 0, SCREEN_WIDTH, HEIGHT(200));
        _view_noData.layer.zPosition = 10;
        _view_noData.hidden = YES;
    }
    return _view_noData;
}




#pragma mark 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
